## Input mode

| Commands | Actions                                                      |
| :------- | ------------------------------------------------------------ |
| a A      | Insert characters to the right of the cursor / current line  |
| i I      | Insert characters to the left of cursor / beginning of  line |
| o O      | Add a new line after /  above current line                   |
| C        | Delete from cursor to the end of the line and insert         |
| c cw ... | 'Change' character / word etc.                               |

## Moving around

| Commands          | Actions                                                    |
| :---------------- | :--------------------------------------------------------- |
| h j k l           | Left down up right                                         |
| H L M             | Start end middle of screen                                 |
| w  b              | Next / Previous word                                       |
| W  B              | Next / Previous word (space seperated)                     |
| e  E              | Move to the end of  word /  end of  word past punctuaion   |
| #G                | Move to the # line                                         |
| [ [ or gg         | Move to the beginning                                      |
| ]] or G           | Move to the end                                            |
| 0  $              | Start / End of line                                        |
| ^                 | First non-blank character of line (same as 0w)             |
| Ctrl-d  Ctrl-u    | Move cursor & screen down / up ½ page                      |
| Ctrl-f  Ctrl-b    | Move one screen down  /  up.   Cursor to first / last line |
| Ctrl-y and Ctrl-e | Moves screen up / down one line.                           |
| gT gt             | Previous / next  tab                                       |
| )  (              | Start of the next / previous sentence                      |
| }  {              | Start of the next / previous paragraph or block of text    |

Ctrl-y Moves screen up one line
Ctrl-e Moves screen down one line

Ctrl-b Moves screen up one page, cursor to last <u>line</u>
Ctrl-f Moves screen down one page, cursor to first line
Ctrl-y and Ctrl-e only change the cursor position if it would be moved off screen

| Commands             | Actions                                              |
| -------------------- | ---------------------------------------------------- |
| x  X                 | Delete a character / delete character  'backspace'   |
| dd   dw  dG  dgg ... | Delete the line the cursor is on / word etc.         |
| #dd                  | Delete the #  of lines following the cursor          |
| d   D                | Delete selection / to the end of sentence            |
| yy   yw   ...        | Copy (yank) a line / word  etc.                      |
| p   P                | Paste (put)  buffer   below / above the current line |
| i                    | 'Inner' with visual                                  |
| w                    | 'Word' with visual                                   |
| viB   vi}            | Select inner block (inside curly braces)             |
| u  u#                | Undo / undo number of times                          |
| Ctrl + r             | Redo                                                 |
| .                    | Repeat last command                                  |

## Marking text (visual mode)

| Commands      | Actions                                   |
| ------------- | ----------------------------------------- |
| v   V  Ctrl+v | Visual  character /  line /  block   mode |
|               |                                           |
|               |                                           |



| Commands        | Actions                                              |
| --------------- | ---------------------------------------------------- |
| /<search_term>  | search and cycle through:  n and N                   |
| :%s/foo/bar/gci | search and replace all occurrences with confirmation |
| :w              | save                                                 |
| Esc + :q!       | force quit Vim discarding all changes                |

## vi mode commands

| Command | Action                                                   |
| ------- | -------------------------------------------------------- |
| Ctrl-L  | Refresh the screen                                       |
| /string | Find text string forward                                 |
| ?string | Find text string backward                                |
| n       | Find forward next string instance after a string search  |
| N       | Find backward next string instance after a string search |

## Command mode commands

| Command     | Action                                                       |
| ----------- | ------------------------------------------------------------ |
| :g/X/s//x/g | Global Search and replace (X=search object x=replace object) |
| :r file     | Import a file into the current file                          |
| :# r file   | Import a file into the current file after line #             |
| :w file     | Write the file to named file                                 |
| :wq   ZZ    | Save the file exit vi                                        |
| :w!         | Force save the file                                          |
| :q!         | Quit vi but don’t save changes                               |

## Some indent commands

```
>>   Indent line by shiftwidth spaces
<<   De-indent line by shiftwidth spaces
5>>  Indent 5 lines
5==  Re-indent 5 lines

>%   Increase indent of a braced or bracketed block (place cursor on brace first)
=%   Reindent a braced or bracketed block (cursor on brace)
<%   Decrease indent of a braced or bracketed block (cursor on brace)
]p   Paste text, aligning indentation with surroundings

=i{  Re-indent the 'inner block', i.e. the contents of the block
=a{  Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block

>i{  Increase inner block indent
<i{  Decrease inner block indent
```

https://web.archive.org/web/20161221161539/http://bullium.com/support/vim.html#move
https://web.archive.org/web/20161225202624/http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
https://www.openvim.com/tutorial.html